import static javax.media.opengl.GL.GL_TRIANGLES;

/**
 * Extends genericGlObject with Triangle.
 * 
 *       Created 27/apr/2013.
 * @author Pietro Bolognesi matr. 227383
 * @author Giorgio Lazzaretti matr. 220232
 *  
 */
public class GlTriangle extends GenericGlObject {
	/**
	 * Side of the triangle
	 */
	protected float l;
	
	/**
	 * Create a new triangle
	 *
	 */
	public GlTriangle(){
		this.l = 0.2f;
		this.ObjectName = "Triangle";
		SetObjectColor(1.0f,1.0f,1.0f);
		this.ToDraw = true;
	}

	/**
	 * Set the side of the triangle.
	 *
	 * @param newL Side.
	 */
	public void SetTriangleDim(float newL){this.l = newL;}
	/**
	 * Returns the side of the triangle.
	 *
	 * @return Side.
	 */
	public float GetTriangleDim(){return this.l;} 

	/**
	 * Draw the triangle.
	 *
	 */
	@Override
	public void DrawObject(){
		if(!this.ToDraw)
			return;
	      // ----- Render a triangle -----

	      this.gl.glColor3f(this.Red, this.Green, this.Blue);
	      this.gl.glBegin(GL_TRIANGLES); // draw using triangles
	      this.gl.glVertex3f(0.0f, this.l, 0.0f);
	      this.gl.glVertex3f(-this.l, -this.l, 0.0f);
	      this.gl.glVertex3f(this.l, -this.l, 0.0f);
	      this.gl.glEnd();
	}
}
